home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Text Processing / Undigest < prev   
Internet Message Format  |  1993-12-30  |  3KB

  1. From: #66 Andrew Brandt <brandt@cs.unc.edu>
  2. Subject: [*] "undigest" for Unix mail 
  3. Date: Thu, 28 Oct 1993 12:01:52 -0400 (EDT) 
  4.  
  5.  
  6. This perl script runs on Unix systems.  It is useful for parsing
  7. digest email.  For example, from inside elm (the Unix mail program)
  8. simply pipe a message thru "undigest".
  9.  
  10. "Undigest" will break all the messages inside the digest into
  11. individual messages and display them.  It does not alter the original
  12. message, it makes a copy.
  13.  
  14. I did not write this, I just use it.
  15.  
  16. I guess this should show up in the Unix dir.
  17.  
  18. -Andy (brandt@cs.unc.edu)
  19.  
  20. ================ cut here, Unix perl script below =================
  21.  
  22. #! /usr/local/bin/perl
  23. # Modified: 14 September 1993
  24. #
  25. #    This is 'digest' a program to run elm on a digest as a folder.
  26. #    Copyright (C) 1990-1993  David J. Camp
  27. #
  28. #    This program is free software; you can redistribute it and/or modify
  29. #    it under the terms of the GNU General Public License as published by
  30. #    the Free Software Foundation; either version 1, or (at your option)
  31. #    any later version.
  32. #
  33. #    This program is distributed in the hope that it will be useful,
  34. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  36. #    GNU General Public License for more details.
  37. #
  38. #    You should have received a copy of the GNU General Public License
  39. #    along with this program; if not, write to the Free Software
  40. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  41. #
  42. # david@campfire.stl.mo.us             David J. Camp         ^      #
  43. # wupost.wustl.edu!campfire!david      +1 314 382 0584     < *    #
  44. # I am a member of:  The League for Programming Freedom.     v      #
  45. # Ask: lpf@uunet.uu.net                "God loves material things." #
  46. #
  47. # from the elm menu, type |digest<return>
  48. #
  49. if (-t STDIN)
  50.     {
  51.     print STDERR "Usage: \"|digest\" from elm menu\n";
  52.     exit 3;
  53.     }
  54. $| = 1;
  55. open (FOLDER, ">/tmp/dig$$");
  56. $hang = 0;
  57. $first = 1;
  58. while (! eof (STDIN))
  59.     {
  60.     if (! $hang)
  61.     {
  62.     $_ = <>;
  63.     }
  64.     $hang = 0;
  65.     if ($first)
  66.         {
  67.         if (! m/^From /)
  68.             {
  69.         print FOLDER "From dummy Wed Feb  29 12:12:12 1990\n";
  70.             }
  71.         $first = 0;
  72.         }
  73.     $match = 0;
  74.     if (/^-[^ ]/)
  75.     { $match = 1; }
  76.     if (/^[0-9]*\)$/)
  77.     { $match = 1; }
  78.     if (/^\([0-9]*\) ----\n$/)
  79.     { $match = 1; }
  80.     if (/^\001\001*\n$/)
  81.     { $match = 1; }
  82.     if (/^============================================================\n$/)
  83.         { $match = 1; }
  84.     if 
  85. (/^=========================================================================\n$/)
  86.     { $match = 1; }
  87.     if 
  88. (/^========================================================================/)
  89.     { $match = 1; }
  90.     if ($match || $first)
  91.         {
  92.     $EB = $_;
  93.     $_ = "";
  94.     for ($ctr = 0; ! (eof() || /[\041-\177]/); $ctr++)
  95.             {
  96.             $_ = <>;
  97.         $headers [ctr] = $_;
  98.             }
  99.     if (/^[^ \t\r\n:]+: /)
  100.         {
  101.         print FOLDER "From dummy Wed Feb  29 12:12:12 1990\n";
  102.         print FOLDER "X-EB: " . $EB ;
  103.         $hang = 0;
  104.         }
  105.     else
  106.         {
  107.         print FOLDER $EB;
  108.         for ($ctr2 = 0; $ctr2 < ctr - 1; $ctr2++)
  109.         {
  110.         print FOLDER $headers [ctr2];
  111.         }
  112.         $hang = 1;
  113.         }
  114.         }
  115.     if (/^- /)
  116.     {
  117.     $_ = substr ($_, 2);
  118.     }
  119.     print FOLDER $_;
  120.     $first = 0;
  121.     }
  122. close (FOLDER);
  123. exec ("chmod 600 /tmp/dig$$; elm -f /tmp/dig$$ <&2 ; /bin/rm -f /tmp/dig$$");
  124.  
  125.  
  126.